
package ifes;

import edu.stanford.nlp.ling.HasWord;
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
import edu.stanford.nlp.parser.lexparser.LexicalizedParserQuery;
import edu.stanford.nlp.process.Tokenizer;
import edu.stanford.nlp.trees.PennTreebankLanguagePack;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.TreebankLanguagePack;
import java.io.StringReader;
import java.util.List;


public class LxCenterNosso {

    private static ParseThread parseThread;

    public static void main(String[] args) {
        TreebankLanguagePack tlp = new PennTreebankLanguagePack();

        int PARSE_TIME = 30;
        String text = "O conto é uma obra de ficção que cria um universo de seres e acontecimentos, de fantasia ou imaginação. Como todos os textos de ficção, o conto apresenta um narrador, personagens, ponto de vista e enredo .";
        Tokenizer<? extends HasWord> toke = tlp.getTokenizerFactory().getTokenizer(new StringReader(text));
        List<? extends HasWord> wordList = toke.tokenize();
        parseThread = new ParseThread(wordList);
        parseThread.start();
    }
}

class ParseThread extends Thread {

    List<? extends HasWord> sentence;
    private boolean successful;

    public ParseThread(List<? extends HasWord> sentence) {
        this.sentence = sentence;
    }

    @Override
    public void run() {
        LexicalizedParser parser = LexicalizedParser.loadModel("/home/ifes/Downloads/lxnosso/cintil.ser.gz");

        LexicalizedParserQuery parserQuery = parser.parserQuery();
        try {
            successful = parserQuery.parse(sentence);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Tree tree = parserQuery.getBestParse();
        tree.pennPrint();
    }
}